package com.zb.controller;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zb.Service.DictionaryService;
import com.zb.Service.LeaveService;
import com.zb.Service.TaskService;
import com.zb.Service.UserService;
import com.zb.entity.Dictionary;
import com.zb.entity.Leave;
import com.zb.entity.User;

@Scope("prototype")
@Component
@RequestMapping("/leave")
public class LeaveController {
	@Resource
	private LeaveService ls;
	@Resource
	private UserService us;
	@Resource
	private DictionaryService ds;
	@Resource
	private TaskService ts;

	@RequestMapping(params = "op=save")
	public String toSave(int userid, int dicid, String starttime,
			String endtime,String content,int roleid,ModelMap modelMap) {
		User u = us.getUserById(userid);
		User ru = us.getUserById(roleid);
		
		Dictionary d = ds.getDictionaryById(dicid);
		Leave l = new Leave();
		l.setUser(u);
		l.setDictionary(d);
		l.setRole(ru);
		l.setStarttime(starttime);
		l.setEndtime(endtime);
		l.setContent(content);
		ls.saveLeave(l);
		int contentid = ls.getMaxId();
		ts.saveTask(userid, 1, contentid, roleid);	
		String str ="已提交";
		modelMap.put("str", str);
		return "leave";

	}

}
